package com.happyclub.lbjdao;

import com.happyclub.pojo.TbProduct;
import com.happyclub.utils.JsonResult;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 高欢
 * @description TODO
 * @date 2019/4/10
 */
public interface Product extends JpaRepository<TbProduct,String> {
    //将先前插入的imgUrl更新成相片ID
    @Modifying
    @Query(value = "update TB_PRODUCT u set u.IMG_URL = :pimgUrl where u.ID = :pid ",nativeQuery = true)
    int updateImgUrl(@Param("pimgUrl") String pimgUrl,@Param("pid") String pid);

    //修改商品上架状态
    @Modifying
    @Query(value = "update TB_PRODUCT u set u.UPPER = :upper where u.ID = :proId",nativeQuery = true)
    int updateProUpper(@Param("upper") Integer upper,@Param("proId") String proId);

    List<TbProduct> findTbProductsByUpper(long upper);

    @Modifying
    @Query(value = "update TB_PRODUCT u set u.LOOK_NUM = u.LOOK_NUM + 1 where u.ID = :fid",nativeQuery = true)
    int updateProLookNum(@Param("fid") String fid);

    @Modifying
    @Query(value = "update TB_PRODUCT u set u.SELL_NUM = :snum where u.ID = :pid",nativeQuery = true)
    int updateSellNum(@Param("snum") long snum,@Param("pid") String pid);
}
